//动画模块
put('animate',function(){
	var nextFrame = window.requestAnimationFrame|| function(callback){
			return window.setTimeout(callback,16);
	};
	var clearFrame = window.cancelAnimationFrame || window.clearTimeout ;
	var timeout = null ;
	var animate = {
		start : function( callback ){
			var func = function(){
				callback() ;
				timeout = nextFrame( func ) ;
			};	
			timeout = nextFrame( func ) ;
		} ,
		stop : function(){
			if( timeout ){ clearFrame( timeout ); }
		}
	} ;
	return animate ;
});	

//获取指定图片的纯黑像素点
put('getPixel',['util'],function(util){
	var canvas = document.createElement('canvas');
	canvas.width = 1500 ;
	canvas.height = 1500 ;
	var ctx = canvas.getContext('2d') ;
	var part = 15;
	
	return function(text,fontSize){		
			ctx.save() ; 
			ctx.font = "Bold " + fontSize+ "px Arial" ;
			ctx.fillStyle = '#000000' ;
			ctx.fillText(text,0,fontSize) ;
			var img = ctx.getImageData(0,0,canvas.width,canvas.height) , pixel = [] , x ,y ;
			for( var i = 0 ; i < img.data.length ; i+=4 ) {		
				x = ( i / 4 ) % img.width ;
				y = parseInt( ( i / 4) / img.width )  ;
				if( x%part!==0 || y%part!==0 ){ continue; }
				if(img.data[i]===0&&img.data[i+1]===0&&img.data[i+2]===0&&img.data[i+3]===255){
					pixel.push([ x , y ]) ;
				}		
			}	
			ctx.restore() ;		
			canvas.width = canvas.width ;	
			return pixel;
		
	} ;
}) ;

put( 'getImageData' , ['util'] , function( util ){
	var canvas = document.createElement('canvas');
	canvas.width = 1500 ;
	canvas.height = 1500 ;
	var ctx = canvas.getContext('2d') ;
	return function(text,fontSize){
		ctx.save() ; 
		ctx.font = "Bold " + fontSize+ "px Arial" ;
		ctx.fillStyle = '#000000' ;
		ctx.fillText(text,0,fontSize) ;	
		return ctx.getImageData(0,0,canvas.width,canvas.height) ;	
	} ;
} ) ;